---
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-conf
  namespace: {{ .Release.Namespace }}
  labels:
    app: prometheus
data:
  prometheus.yml: |
    global:
      scrape_interval: 10s
      scrape_timeout: 10s
    rule_files:
       - "/config/*"
    scrape_configs:
    - job_name: kubernetes-pods
      kubernetes_sd_configs:
      - role: pod
        namespaces:
          names:
          - {{ .Release.Namespace }}
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        action: keep
        regex: true
      - source_labels: [__meta_kubernetes_pod_ip, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+)
        replacement: $1:$2
        target_label: __address__
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
      - action: labelmap
        regex: __meta_kubernetes_pod_label_(.+)
      - source_labels: [__meta_kubernetes_namespace]
        action: replace
        target_label: kubernetes_namespace
      - source_labels: [__meta_kubernetes_pod_name]
        action: replace
        target_label: kubernetes_pod_name
    {{- range $yandex := .Values.yandex_cloud_services }}
    - job_name: yandex_service_{{ $yandex.service }}
      metrics_path: '/monitoring/v2/prometheusMetrics'
      params:
        folderId:
        - {{ $yandex.folderId }} 
        service:
        - {{ $yandex.service }}
      scrape_interval: {{ $yandex.scrape_interval | default "60s" | quote }}
      bearer_token: {{ $yandex.bearer_token }} 
      static_configs:
      - targets: ['monitoring.api.cloud.yandex.net']
        labels:
          folderId: {{ $yandex.folderId }} 
          service: {{ $yandex.serviceId }} 
    {{ end -}}
